package com.ruoyi.web.controller.organization;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.organization.domain.BaseLocation;
import com.ruoyi.organization.service.IBaseLocationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 办公地点Controller
 * 
 * @author hango
 * @date 2025-10-10
 */
@RestController
@RequestMapping("/organization/location")
public class BaseLocationController extends BaseController
{
    @Autowired
    private IBaseLocationService baseLocationService;

    /**
     * 查询办公地点列表
     */
    @PreAuthorize("@ss.hasPermi('organization:organization:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseLocation baseLocation)
    {
        startPage();
        List<BaseLocation> list = baseLocationService.selectBaseLocationList(baseLocation);
        return getDataTable(list);
    }

    /**
     * 导出办公地点列表
     */
    @PreAuthorize("@ss.hasPermi('organization:organization:export')")
    @Log(title = "办公地点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseLocation baseLocation)
    {
        List<BaseLocation> list = baseLocationService.selectBaseLocationList(baseLocation);
        ExcelUtil<BaseLocation> util = new ExcelUtil<BaseLocation>(BaseLocation.class);
        util.exportExcel(response, list, "办公地点数据");
    }

    /**
     * 获取办公地点详细信息
     */
    @PreAuthorize("@ss.hasPermi('organization:organization:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseLocationService.selectBaseLocationById(id));
    }

    /**
     * 新增办公地点
     */
    @PreAuthorize("@ss.hasPermi('organization:organization:add')")
    @Log(title = "办公地点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseLocation baseLocation)
    {
        return toAjax(baseLocationService.insertBaseLocation(baseLocation));
    }

    /**
     * 修改办公地点
     */
    @PreAuthorize("@ss.hasPermi('organization:organization:edit')")
    @Log(title = "办公地点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseLocation baseLocation)
    {
        return toAjax(baseLocationService.updateBaseLocation(baseLocation));
    }

    /**
     * 删除办公地点
     */
    @PreAuthorize("@ss.hasPermi('organization:organization:remove')")
    @Log(title = "办公地点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseLocationService.deleteBaseLocationByIds(ids));
    }
}
